package com.jyw.business.de.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jyw.business.de.domain.dto.web.DemandOperDto;
import com.jyw.business.de.domain.dto.web.TaskMakeDto;
import com.jyw.business.de.domain.dto.web.TaskPageDto;
import com.jyw.business.de.domain.vo.web.TaskDetailVO;
import com.jyw.business.de.domain.vo.web.TaskPageVO;
import com.jyw.business.de.domain.vo.web.TaskProcessVO;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.core.domain.model.SimpleDto;
import com.jyw.common.core.page.BasePage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jyw.common.annotation.Log;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.core.domain.AjaxResult;
import com.jyw.common.enums.BusinessType;
import com.jyw.business.de.domain.DeTaskInfo;
import com.jyw.business.de.service.IDeTaskInfoService;
import com.jyw.common.utils.poi.ExcelUtil;
import com.jyw.common.core.page.TableDataInfo;

/**
 * 需求-任务Controller
 * 
 * @author ruoyi
 * @date 2024-02-19
 */
@RestController
@RequestMapping("/de/task/info")
@Api(tags = "需求任务")
public class DeTaskInfoController extends BaseController
{
    @Autowired
    private IDeTaskInfoService deTaskInfoService;

    /**
     * 查询需求-任务列表
     */
    @PostMapping("/list")
    @ApiOperation("需求任务分页查询")
    public TableDataInfo<TaskPageVO> list(@RequestBody TaskPageDto dto, BasePage page)
    {
        startPage();
        List<TaskPageVO> list = deTaskInfoService.taskPage(dto);
        return getDataTable(list);
    }

    /**
     * 任务接收
     */
    @PreAuthorize("@ss.hasPermi('de:task:info:accept')")
    @PutMapping("/accept")
    @ApiOperation("任务接收")
    public CommonResult accept(@RequestBody SimpleDto<Long> dto)
    {
        deTaskInfoService.accept(dto);
        return CommonResult.success();
    }

    /**
     * 任务退回
     */
    @PreAuthorize("@ss.hasPermi('de:task:info:back')")
    @PutMapping("/back")
    @ApiOperation("任务退回")
    public CommonResult back(@RequestBody DemandOperDto dto)
    {
        deTaskInfoService.back(dto);
        return CommonResult.success();
    }

    /**
     * 任务退回
     */
    @PreAuthorize("@ss.hasPermi('de:task:info:pause')")
    @PutMapping("/pause")
    @ApiOperation("任务暂停")
    public CommonResult pause(@RequestBody DemandOperDto dto)
    {
        deTaskInfoService.pause(dto);
        return CommonResult.success();
    }

    /**
     * 任务终止
     */
    @PreAuthorize("@ss.hasPermi('de:task:info:termination')")
    @PutMapping("/termination")
    @ApiOperation("任务终止")
    public CommonResult termination(@RequestBody DemandOperDto dto)
    {
        deTaskInfoService.termination(dto);
        return CommonResult.success();
    }

    /**
     * 任务终止
     */
    @PreAuthorize("@ss.hasPermi('de:task:info:open')")
    @PutMapping("/open")
    @ApiOperation("任务开启")
    public CommonResult termination(@RequestBody SimpleDto<Long> dto)
    {
        deTaskInfoService.open(dto);
        return CommonResult.success();
    }

    /**
     * 任务处理
     */
    @PreAuthorize("@ss.hasPermi('de:task:info:make')")
    @PutMapping("/make")
    @ApiOperation("任务处理")
    public CommonResult make(@RequestBody TaskMakeDto dto)
    {
        deTaskInfoService.make(dto);
        return CommonResult.success();
    }

    /**
     * 任务处理
     */
    @PreAuthorize("@ss.hasPermi('de:task:info:hurry')")
    @PutMapping("/hurry")
    @ApiOperation("任务催办")
    public CommonResult hurry(@RequestBody SimpleDto<Long> dto)
    {
        deTaskInfoService.hurry(dto);
        return CommonResult.success();
    }

    /**
     * 获取需求-任务详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("任务详情")
    public CommonResult<TaskDetailVO> getInfo(@PathVariable("id") Long id)
    {
        return CommonResult.success(deTaskInfoService.getInfo(id));
    }

    /**
     * 获取需求-任务详细信息
     */
    @GetMapping(value = "process/{id}")
    @ApiOperation("任务详情")
    public CommonResult<List<TaskProcessVO>> getProcessInfo(@PathVariable("id") Long id)
    {
        return CommonResult.success(deTaskInfoService.getProcessInfo(id));
    }

}
